package cc.xulu.controller;

import com.jfinal.core.Controller;

import cc.xulu.model.*;

public class UserController extends Controller {
	public void index() {
		setAttr("userPage", User.dao.paginate(getParaToInt(0, 1), 10, "select *", "from user order by id asc"));
		render("list.html");
	}
	
	public void add() {
	    render("edit.html");
	}
	
	public void save() {
		User user = getModel(User.class);
		if (user.get("id") == null) {
			user.save();
		} else {
			user.update();
		}
		redirect("/user");
	}
	
	public void edit() {
		setAttr("user", User.dao.findById(getParaToInt()));
		render("edit.html");
	}
	
	public void update() {
		getModel(User.class).update();
		redirect("/user");
	}
	
	public void delete() {
		User.dao.deleteById(getParaToInt());
		redirect("/user");
	}
}
